
component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="PermissionDelegate" type="it.millemultimedia.easyBlog.delegate.PermissionDelegate";

	public it.millemultimedia.easyBlog.service.PermissionService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.PermissionValidator function getValidator(){
		
		return getPermissionDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Permission[] function createPermissionList( required String list, required String propertyName ){
		
		return getPermissionDelegate().createList( arguments.list, arguments.propertyName );
	}
	
	public it.millemultimedia.easyBlog.model.Permission function new(){
		
		return getPermissionDelegate().createInstance();
	}
	
	public it.millemultimedia.easyBlog.model.Permission function getPermission( required Any Permission ){
		
		return getPermissionDelegate().read( arguments.Permission );
	}
	
	public it.millemultimedia.easyBlog.model.Permission[] function getPermissions( required Any Permission ){
		
		return getPermissionDelegate().list( arguments.Permission );
	}
	
	public boolean function permissionExists( required Any Permission ){
		var result = getPermissionDelegate().list( arguments.Permission );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function savePermission( required Any Permission ){
	
		transaction{
		
			try{
				
				
				if( arguments.Permission.getidPermission()  eq 0 ){
				
					this.createPermission( arguments.Permission );
				
				}else if( arguments.Permission.getIdPermission() gt 0 ){
				
					this.updatePermission( arguments.Permission );
				
				}else{
				
					throw( message="Permission id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createPermission( required Any Permission ){
	
		transaction{
		
			try{
			
				getPermissionDelegate().create( arguments.Permission );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updatePermission( required Any Permission ){
	
		transaction{
		
			try{
			
				getPermissionDelegate().update( arguments.Permission );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deletePermission( required Any Permission ){
	
		transaction{
		
			try{
			
				getPermissionDelegate().delete( arguments.Permission );
				
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
